package com.jtbd.client;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ObjectMapperClient {
    private static final ObjectMapperClient instance = new ObjectMapperClient();

    private ObjectMapper objectMapper;

    private ObjectMapperClient() {
        objectMapper = new ObjectMapper();
    }

    public static ObjectMapperClient getInstance() {
        return instance;
    }

    public static ObjectMapper getObjectMapper() {
        return instance.objectMapper;
    }

    public static <T> T readValue(String s, TypeReference<T> valueTypeRef) throws JsonProcessingException {
        return instance.objectMapper.readValue(s, valueTypeRef);
    }

    public static <T> T readValue(String s, Class<T> aClass) throws JsonProcessingException {
        return instance.objectMapper.readValue(s, aClass);
    }

    public static String writeValue(Object o) throws JsonProcessingException {
        return instance.objectMapper.writeValueAsString(o);
    }
}
